//https://leetcode.cn/problems/check-completeness-of-a-binary-tree/description/


class Solution {
public:
    bool isCompleteTree(TreeNode* root) {
        // 层序遍历的辅助利器
        queue<TreeNode*> q;
        // 记录是否已经遍历到null结果
        bool reachNull = false;
        q.push(root);
        while (!q.empty())
        {
            TreeNode* curr = q.front();
            q.pop();
            if (curr == nullptr)
            {
                // 发现空结点了
                reachNull = true;
                continue;
            }
            else
            {
                // 发现null结点后出现非空结点，发现不完全了
                if (reachNull)
                {
                    return false;
                }
                // 继续遍历左右节点
                q.push(curr->left);
                q.push(curr->right);
            }
        }
        return true;
    }
};